﻿package frEngine.loaders.particleSub
{
    import frEngine.loaders.particleSub.particleInstance.*;

    public class SphereEmitter extends EmitterObject
    {
        private var _R:Number = 0;
        private var _rate:Number;
        private var _instance3dArr:Array;
        private var _segment:int = 30;

        public function SphereEmitter(param1:Number, param2:Number, param3:String, param4:String)
        {
            this._R = param1;
            this._rate = param2;
            super(param3, param4);
            return;
        }// end function

        override public function get meshData() : MeshBase
        {
            if (!_meshData && !hasDisposed)
            {
                _meshData = new SphereData(this._R);
            }
            return _meshData;
        }// end function

        override protected function processVolume(param1:int) : void
        {
            this.processCurve(param1);
            var _loc_2:* = randnomArr2[param1];
            var _loc_3:* = Math.sqrt(_loc_2);
            _vect3d.x = _vect3d.x * _loc_3;
            _vect3d.y = _vect3d.y * _loc_3;
            _vect3d.z = _vect3d.z * _loc_3;
            return;
        }// end function

        override protected function processAxis(param1:int) : void
        {
            _vect3d.y = 0;
            _vect3d.x = 0;
            _vect3d.z = 0;
            return;
        }// end function

        override protected function processCurve(param1:int) : void
        {
            var _loc_2:* = randnomArr0[param1];
            var _loc_3:* = randnomArr1[param1];
            var _loc_4:* = 2 * Math.PI * _loc_2;
            _vect3d.y = this._R * this._rate * Math.sin(_loc_4);
            var _loc_5:* = this._R * this._rate * Math.cos(_loc_4);
            var _loc_6:* = 2 * Math.PI * _loc_3;
            _vect3d.x = _loc_5 * Math.cos(_loc_6);
            _vect3d.z = _loc_5 * Math.sin(_loc_6);
            return;
        }// end function

        override protected function processEdage(param1:int) : void
        {
            this.processCurve(param1);
            return;
        }// end function

        override protected function processVertex(param1:int) : void
        {
            this.processCurve(param1);
            return;
        }// end function

        override public function getObject3d()
        {
            if (emitterPosType == EmitterPosType.TextureRGB)
            {
                return this.meshData;
            }
            if (!this._instance3dArr)
            {
                this._instance3dArr = new Array();
                this.createLineData0(this._instance3dArr);
                this.createLineData1(this._instance3dArr);
                this.createLineData2(this._instance3dArr);
            }
            return this._instance3dArr;
        }// end function

        private function createLineData0(param1:Array) : void
        {
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_2:* = new Array();
            var _loc_3:* = Math.PI * 2 / this._segment;
            var _loc_4:Number = 0;
            var _loc_5:int = 0;
            while (_loc_5 <= this._segment)
            {
                
                _loc_4 = _loc_3 * _loc_5;
                _loc_6 = Math.cos(_loc_4) * this._R;
                _loc_7 = Math.sin(_loc_4) * this._R;
                _loc_2.push(_loc_6, 0, _loc_7);
                _loc_5++;
            }
            param1.push(_loc_2);
            return;
        }// end function

        private function createLineData1(param1:Array) : void
        {
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_2:* = new Array();
            var _loc_3:* = Math.PI * 2 / this._segment;
            var _loc_4:Number = 0;
            var _loc_5:int = 0;
            while (_loc_5 <= this._segment)
            {
                
                _loc_4 = _loc_3 * _loc_5;
                _loc_6 = Math.cos(_loc_4) * this._R;
                _loc_7 = Math.sin(_loc_4) * this._R;
                _loc_2.push(_loc_6, _loc_7, 0);
                _loc_5++;
            }
            param1.push(_loc_2);
            return;
        }// end function

        private function createLineData2(param1:Array) : void
        {
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_2:* = new Array();
            var _loc_3:* = Math.PI * 2 / this._segment;
            var _loc_4:Number = 0;
            var _loc_5:int = 0;
            while (_loc_5 <= this._segment)
            {
                
                _loc_4 = _loc_3 * _loc_5;
                _loc_6 = Math.cos(_loc_4) * this._R;
                _loc_7 = Math.sin(_loc_4) * this._R;
                _loc_2.push(0, _loc_6, _loc_7);
                _loc_5++;
            }
            param1.push(_loc_2);
            return;
        }// end function

    }
}
